#!/bin/sh

if [ -z "$1" ]; then
	echo "Missing argument. Use: $0 <version>"
	exit 1
fi

TMPDIR=$(mktemp -d)

OLDCWD=$PWD

cd $TMPDIR
echo "Downloading XPI files..."
wget -np -nH -r --cut-dirs 7 -A "*.xpi" http://ftp.mozilla.org/pub/firefox/releases/$1/linux-i686/xpi/

cd $OLDCWD

for f in $TMPDIR/*.xpi; do
	md5=$(md5sum $f | awk '{ print $1 }')
	sha256=$(sha256sum $f | awk '{ print $1 }')
	lang_code=$(echo $f | sed "s,$TMPDIR/\([^\.]*\).xpi,\1,g" | tr '[A-Z]' '[a-z]')

cat > firefox-l10n-${lang_code}_$1.bb <<EOF
# Copyright (C) 2009-2018, O.S. Systems Software Ltda. All Rights Reserved
# Released under the MIT license (see packages/COPYING)

require firefox-l10n.inc

SRC_URI[md5sum] = "$md5"
SRC_URI[sha256sum] = "$sha256"
EOF
done

rm -rf $TMPDIR
